package record;

import request.*;

/**
 * @author Sean Freitag, Stephan Jossie, Jacob Freemyer
 *
 */
public class RecordFactory {

	/** 
	 * 
	 */
	public RecordFactory(){
		
	}
	
	/**
	 * @param request
	 * @return
	 */
	public Record getRecord(Request request){
		
		if(request == null)
			return null;
		else if(request instanceof NewUserRequest){
			NewUserRequest req = (NewUserRequest) request;
			return new UserRecord(req.getFirstName(), req.getLastName(), req.getEmailAddress(), 
								  req.getPassword(), req.getCreditCardNum(), req.getCreditCardSecurityCode(), 
								  req.getCreditCardBrand());
		}else if(request instanceof NewProjectRequest){
			NewProjectRequest req = (NewProjectRequest) request;
			return new ProjectRecord(req.getName());
		}else if(request instanceof AllProjectsRequest){
			AllProjectsRequest req = (AllProjectsRequest) request;
			return new AllProjectsRecord(req.getProjects());
		}else if(request instanceof RemoveProjectRequest){
			RemoveProjectRequest req = (RemoveProjectRequest) request;
			return new AllProjectsRecord(req.getProjects());
		}else if(request instanceof ChangeCredentialsRequest){
			((ChangeCredentialsRequest) request).getUserRecord().changePassword(((ChangeCredentialsRequest) request).getPassword());
			return ((ChangeCredentialsRequest) request).getUserRecord();
		}
		else{
			return null;
		}
	}
	
}
